#pragma rtGlobals=1		// Use modern global access method.

//Menu "Macros"
//	"Update Spectrometry Package", /Q, Unload_Procedures_Update()
//End

Function Unload_Procedures_Update()
Execute/P/Q/Z "DELETEINCLUDE \"Convolution\""
Execute/P/Q/Z "DELETEINCLUDE \"Data_Analysis\""
Execute/P/Q/Z "DELETEINCLUDE \"Factor_Analysis\""
Execute/P/Q/Z "DELETEINCLUDE \"hard_XPS_processing\""
Execute/P/Q/Z "DELETEINCLUDE \"maxent\""
Execute/P/Q/Z "DELETEINCLUDE \"Optimization\""
Execute/P/Q/Z "DELETEINCLUDE \"Spectrometry\""
//Execute/P/Q/Z "DELETEINCLUDE \"update_Procedures\""
Execute/P/Q/Z "DELETEINCLUDE \"Utility_Procedures\""
Execute/P/Q/Z "DELETEINCLUDE \"xps_conv\""
Execute/P/Q/Z "DELETEINCLUDE \"XPSbackground\""

Execute/P/Q/Z "COMPILEPROCEDURES "



Execute/P/Q/Z "update_Procedures()"
end

Function update_Procedures()

PathInfo procedures_Locations
if(V_flag == 0)
	NewPath/C/Q/O procedures_Locations
endif
String directory_List = FetchURL("http://piper-lab-code.googlecode.com/svn/trunk/")
String procedure_List = ""
Variable p1, p2
Do

	p1 = strsearch(directory_List, "<a href=\"", p1+1) 
	p2 = strsearch(directory_List,"\">", p2+1)

	if(stringmatch(directory_List[p1+9,p2-1],"*.ipf"))
		procedure_List = procedure_List + directory_List[p1+9,p2-1] + ";"
	endif

while(p1 != -1)

Variable p3

Do
	String procedure_Grab = ReplaceString("\r\n",FetchURL("http://piper-lab-code.googlecode.com/svn/trunk/" + stringfromlist(p3, procedure_List)),"\r")
	String notebookName = UniqueName(ReplaceString(".ipf",stringfromlist(p3, procedure_List), ""),10,1)
	If(stringmatch(stringfromlist(p3, procedure_List), "update_Procedures.ipf") || stringmatch(stringfromlist(p3, procedure_List), "Load_Spectrometry_Procedures.ipf"))
	else
		NewNoteBook /V=0/F=0/N=$notebookName
		NoteBook $notebookName, text=procedure_Grab
		SaveNoteBook /O/P=procedures_Locations/S=2 $notebookName as stringfromlist(p3, procedure_List)
		DoWindow/K $notebookName
	endif
	p3+=1
while(p3 < ItemsInList(procedure_List))

LoadProcedures_Shawn#Load_Spectrometry_Procedures()
end